package com.example.service.web;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.service.business.Foo;
import com.example.service.business.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author karidyang
 */
@RestController
@Slf4j
public class HelloController {
    @Autowired
    private HelloService helloService;

    @Value("${didispace.title:}")
    private String title;

    @SentinelResource(value = "/sayHello", blockHandler = "blockHandlerHello")
    @RequestMapping("/sayHello")
    public String say(@RequestBody Foo foo) {
        return helloService.doSomething(foo);
    }

    @GetMapping("/dash")
    public String dash() {
        return "title="+ title;
    }

    public String blockHandlerHello(Foo foo, BlockException e) {
        return "限流";
    }
}
